package model

import (
	"log"
	"time"
)

type Users struct {
	Id           int       `xorm:"not null pk autoincr INT(10)"`
	CreatedAt    time.Time `xorm:"TIMESTAMP created"`
	UpdatedAt    time.Time `xorm:"TIMESTAMP updated"`
	UserName     string    `xorm:"not null unique VARCHAR(12)"`
	UserPassWord string    `xorm:"not null VARCHAR(40)"`
	LoginIp      string    `xorm:"VARCHAR(255)"`
	//LoginTime    time.Time `xorm:"TIMESTAMP"`
	//IsActive     int       `xorm:"not null default 0 INT(11)"`
	//UserInfoId   int       `xorm:"not null index INT(10)"`
}

func QueryUser() []Users {
	var user []Users
	err := DB.Where("UserName=?", "test").Find(&user)

	if err != nil {
		log.Println("QueryUser ", err)
	}
	log.Println("Successful")
	return user
}

func InsertUser(user Users) error {

	_, err := DB.Insert(user)

	if err != nil {

		return err
	}
	return nil

}

func FindUser(u string) (bool, error) {
	var user Users

	b, err := DB.Where("UserName=?", u).Get(&user)

	return b, err

}

func DelUser(id int64) (int64, error) {
	var user Users
	i, err := DB.Where("id=?", id).Delete(user)

	return i, err
}
